

#include <dpl/log.h>

D_LOG_DOMAIN(atomic_test,"this is a case, how to use");


int test_atomic()
{
	dpl_i("Enter test!");
	dpl_pool_t *pool;
	dpl_atomic_t *atomic_var;
	dpl_status_t rc;


	/* create() */
	rc = dpl_atomic_create(pool, 111, &atomic_var);
	if (rc != 0) {
	    return -20;
	}

	/* get: check the value. */
	if (dpl_atomic_get(atomic_var) != 111)
	    return -30;

	/* increment. */
	dpl_atomic_inc(atomic_var);
	if (dpl_atomic_get(atomic_var) != 112)
	    return -40;

	/* decrement. */
	dpl_atomic_dec(atomic_var);
	if (dpl_atomic_get(atomic_var) != 111)
	    return -50;

	/* set */
	dpl_atomic_set(atomic_var, 211);
	if (dpl_atomic_get(atomic_var) != 211)
	    return -60;

	/* add */
	dpl_atomic_add(atomic_var, 10);
	if (dpl_atomic_get(atomic_var) != 221)
	    return -60;

	/* check the value again. */
	if (dpl_atomic_get(atomic_var) != 221)
	    return -70;

	/* destroy */
	rc = dpl_atomic_destroy(atomic_var);
	if (rc != 0)
	    return -80;

    
	return 0;
}